package com.bjpowerndoe.ylb.web.model;

import com.bjpowerndoe.ylb.web.enums.CodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel(value = "应答结果",description = "服务器统一应答结果")
public class CommonResult {
    @ApiModelProperty(name = "code",value = "自定义应答码")
    private int code;//自定义应答码,1000表示成功,其他是错误
    @ApiModelProperty(value = "code的解释说明")
    private String msg;// 对code的解释说明

    @ApiModelProperty(value = "应答数据")
    private Object info;// 数据

    public void setCodeEnum(CodeEnum codeEnum) {
        this.code = codeEnum.getCode();
        this.msg = codeEnum.getText();
    }

    public static CommonResult ok(){
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(CodeEnum.OK.getCode());
        commonResult.setMsg(CodeEnum.OK.getText());
        commonResult.setInfo("");
        return commonResult;
    }

    public static CommonResult ok(Object info){
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(CodeEnum.OK.getCode());
        commonResult.setMsg(CodeEnum.OK.getText());
        commonResult.setInfo(info);
        return commonResult;
    }

    public static CommonResult fail(CodeEnum codeEnum){
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(CodeEnum.OK.getCode());
        commonResult.setMsg(CodeEnum.OK.getText());
        commonResult.setInfo("");
        return commonResult;
    }
}
